Imports Crystal.DatabaseManagement.BusinessLayer
Imports Infragistics.Win.UltraWinGrid
Imports Infragistics.Documents.Excel
Imports System.Threading
Imports Crystal.CLL
Imports Infragistics.Win.UltraWinGrid.ExcelExport
Imports DevExpress.Utils
Imports DevExpress.XtraEditors
Imports System.ComponentModel
Imports Infragistics.Win.UltraMessageBox
Imports Infragistics.Win.UltraWinEditors
Imports Crystal.CustomControls.Controls
Imports Infragistics.Win



Public Class frmInvestorManagement
    Inherits BaseForm
#Region "Declare"
    Delegate Sub SetTextBoxval(ByVal lbl As Label, ByVal text As String)
    Delegate Sub GenricDelegate(ByVal val As Integer)
    Delegate Sub SearchFilterInvestorDelegate()
    Delegate Sub ControlVisiblityDelegate(ByVal isVisible As Boolean)
    Private _SearchField As String
    Private _SelectedValue As String
    Private _IsStoped As Boolean
    Private _BigInt As Int64 = 9223372036854775807
    Private _Filename As String
    Private _OnLoad = False
    Private _IsThreadAborted As Boolean
    Delegate Sub ControlVisiblityImportDelegate(ByVal isVisible As Integer)
    Delegate Sub GridBind(ByVal Dt As DataTable)
    Private LstModiFiedUserId As New List(Of Integer)
    Private _NullField As String = "--------"
    Private searchedValue As String = String.Empty
    Private rowIndex As Integer
#End Region

#Region "Load"
    Private _Thread As Thread

    Private Sub frmInvestorManagement_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
        If IsChildFormOpened() = False Then
            e.Cancel = True
        End If
    End Sub

    Private Sub frmInvestorManagement_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Try
            LoadFunctionality()
        Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try
    End Sub

    Private Sub LoadFunctionality()
        txtSearchIn.Text = MessageManager.GetMessage("DEFAULTSEARCHTEXT")
        ShowDefaultSelectedColumns()
        DefaultDisableCheckedColumns()
        cmbSearchField.DataSource = LoadSearchField()
        _SearchField = cmbSearchField.SelectedValue
        _OnLoad = True
        rdAll.Checked = True
        _OnLoad = False
        cmbSearchField.SelectedItem = "Investor Name"
        grdInvestors.ContextMenu = New ContextMenu()
        Me.grdInvestors.DisplayLayout.Override.CellClickAction = CellClickAction.CellSelect
        DisableButtonEditDelete(False)
        DisableRightClickInfTextEditor(txtSearchIn)

    End Sub
#End Region

#Region "Methods"

    Private Sub DisableButtonEditDelete(ByVal bool As Boolean)
        btnEdit.Enabled = bool
        btnDelete.Enabled = bool
        btnExport.Enabled = bool
    End Sub

    Private Sub SetTextvalue(ByVal lbl As Label, ByVal val As String)
        lbl.Text = val
    End Sub

    ''' <summary>
    ''' Creates a delgate for search Investor
    ''' </summary>
    ''' <remarks></remarks>

    Private Sub LoadInvestorSearch()
        Dim LoadInvestor As SearchFilterInvestorDelegate = New SearchFilterInvestorDelegate(AddressOf OnLoadInvestors)
        Try
            cmbSearchField.Focus()
            Me.BeginInvoke(LoadInvestor)

        Catch ex As Exception
            MessageBox.Show(ex.Message, mstrMsgBoxCaption, MessageBoxButtons.OK, MessageBoxIcon.Information)
        Finally
            LoadInvestor = Nothing
            cmbSearchField.Focus()
        End Try
    End Sub

    Private Sub LoadSearchFields()
        Dim CInvestorDetails As New cInvestorDetails
        Dim searchField As New DataSet
        searchField = CInvestorDetails.GetColumnsSearchField()
        cmbSearchField.DataSource = searchField.Tables(0)
        cmbSearchField.DisplayMember = "COLUMN_NAME"
        cmbSearchField.ValueMember = "COLUMN_NAME"
        cmbSearchField.SelectedIndex = 2
    End Sub

    Private Function LoadSearchField() As List(Of String)
        Dim lField As New List(Of String)
        If uchkStatus.Checked = True Then
            lField.Add(uchkStatus.Text)
        End If
        If chkInvestorID.Checked Then
            lField.Add(chkInvestorID.Text)
        End If
        If uchkInvestorName.Checked Then
            lField.Add(uchkInvestorName.Text)
        End If
        If chkWebsite.Checked Then
            lField.Add(chkWebsite.Text)
        End If
        If chkPrincipalInvestor.Checked Then
            lField.Add(chkPrincipalInvestor.Text)
        End If
        If chkType.Checked Then
            lField.Add(chkType.Text)
        End If
        If chkStyle.Checked Then
            lField.Add(chkStyle.Text)
        End If
        If chkTurnover.Checked Then
            lField.Add(chkTurnover.Text)
        End If
        If chkCity.Checked Then
            lField.Add(chkCity.Text)
        End If
        If chkCountry.Checked Then
            lField.Add(chkCountry.Text)
        End If
        If chkParent.Checked Then
            lField.Add(chkParent.Text)
        End If
        If chkUltimateParent.Checked Then
            lField.Add(chkUltimateParent.Text)
        End If
        If chkMasterType.Checked Then
            lField.Add(chkMasterType.Text)
        End If
        If chkActivist.Checked Then
            lField.Add("Activist")
        End If
        If chkLastReportDate.Checked Then
            lField.Add("Last Report Date")
        End If
        If chkEquityAssets.Checked Then
            lField.Add("Equity Assets")
        End If
        If chkStreet1.Checked Then
            lField.Add("Street1")
        End If
        If chkStreet2.Checked Then
            lField.Add("Street2")
        End If

        If chkState.Checked Then
            lField.Add("State")
        End If
        If chkRegion.Checked Then
            lField.Add("Region")
        End If

        If chkMobile.Checked Then
            lField.Add("Mobile")
        End If
        If chkTelephone.Checked Then
            lField.Add("Telephone")
        End If
        If chkExt.Checked Then
            lField.Add("Ext")

        End If
        If chkFax.Checked Then
            lField.Add("Fax")
        End If

        If chkFax2.Checked Then
            lField.Add("Fax2")
        End If
        If chkEmail.Checked Then
            lField.Add("Email")
        End If

        lField.Add(_NullField)

        If uchkStatus.Checked = False Then
            lField.Add(uchkStatus.Text)
        End If
        If chkInvestorID.Checked = False Then
            lField.Add(chkInvestorID.Text)
        End If
        If uchkInvestorName.Checked = False Then
            lField.Add(uchkInvestorName.Text)
        End If
        If chkWebsite.Checked = False Then
            lField.Add(chkWebsite.Text)
        End If
        If chkPrincipalInvestor.Checked = False Then
            lField.Add(chkPrincipalInvestor.Text)
        End If
        If chkType.Checked = False Then
            lField.Add(chkType.Text)
        End If
        If chkStyle.Checked = False Then
            lField.Add(chkStyle.Text)
        End If
        If chkTurnover.Checked = False Then
            lField.Add(chkTurnover.Text)
        End If
        If chkCity.Checked = False Then
            lField.Add(chkCity.Text)
        End If
        If chkCountry.Checked = False Then
            lField.Add(chkCountry.Text)
        End If
        If chkParent.Checked = False Then
            lField.Add(chkParent.Text)
        End If
        If chkUltimateParent.Checked = False Then
            lField.Add(chkUltimateParent.Text)
        End If
        If chkMasterType.Checked = False Then
            lField.Add(chkMasterType.Text)
        End If
        If chkActivist.Checked = False Then
            lField.Add("Activist")
        End If
        If chkLastReportDate.Checked = False Then
            lField.Add("Last Report Date")
        End If
        If chkEquityAssets.Checked = False Then
            lField.Add("Equity Assets")
        End If
        If chkStreet1.Checked = False Then
            lField.Add("Street1")
        End If
        If chkStreet2.Checked = False Then
            lField.Add("Street2")
        End If

        If chkState.Checked = False Then
            lField.Add("State")
        End If
        If chkRegion.Checked = False Then
            lField.Add("Region")
        End If

        If chkMobile.Checked = False Then
            lField.Add("Mobile")
        End If
        If chkTelephone.Checked = False Then
            lField.Add("Telephone")
        End If
        If chkExt.Checked = False Then
            lField.Add("Ext")

        End If
        If chkFax.Checked = False Then
            lField.Add("Fax")
        End If

        If chkFax2.Checked = False Then
            lField.Add("Fax2")
        End If
        If chkEmail.Checked = False Then
            lField.Add("Email")
        End If

        Return lField
    End Function

    Private Sub CheckBoxChangeSearchField()
        If txtSearchIn.Text.Trim <> MessageManager.GetMessage("DEFAULTSEARCHTEXT").Trim Or txtSearchIn.Text.Trim <> MessageManager.GetMessage("DEFAULTDATEFORMAT").Trim Then
            searchedValue = txtSearchIn.Text
        End If
        If cmbSearchField.SelectedValue = _NullField Then
            _SelectedValue = "Investor Name"
        Else
            _SelectedValue = cmbSearchField.SelectedValue
        End If
        cmbSearchField.DataSource = LoadSearchField()
        cmbSearchField.SelectedItem = _SelectedValue
        If searchedValue.Length > 0 Then
            txtSearchIn.Text = searchedValue

        End If
    End Sub

    ''' <summary>
    ''' Calll the method for getting Investot with top option
    ''' </summary>
    ''' <remarks></remarks>

    Private Sub OnLoadInvestors()
        Dim CInvestorDetails As New cInvestorDetails
        Dim Count As Integer
        Dim RowID As Integer = 0
        Dim Investor As New DataTable
        Dim MergInvestor As New DataTable
        Dim IDR As IDataReader = Nothing
        Dim i As Integer = 0
        Dim Criteria As Short
        Dim dv As DataView
        Try
            If (Me.IsDisposed) Then Exit Sub
            txtSearchIn.Enabled = False
            cmbSearchField.Enabled = False
            Application.DoEvents()
            Count = CInvestorDetails.GetInvestorCount()
            If Count = 0 Then
                grdInvestors.DataSource = New DataTable
                btnDelete.Enabled = False
                Dim poMsgInfo As New Infragistics.Win.UltraMessageBox.UltraMessageBoxInfo
                poMsgInfo.Text = MessageManager.GetMessage("NORECORD")
                poMsgInfo.Caption = mstrMsgBoxCaption
                poMsgInfo.Buttons = MessageBoxButtons.OK
                poMsgInfo.Icon = MessageBoxIcons.Information

                UltraMessageBoxManager1.ShowMessageBox(poMsgInfo)
                'MessageBox.Show(, , MessageBoxButtons.OK,MessageBoxIcon.Information)
                lblTotalInvestor.Text = "Total investors:- 0"
                Exit Sub
            End If
            'This will ascertain whether the search criteria is begin with or contains
            Criteria = SearchCriteria.Contains
            '*************************************************************

            For i = 0 To Count
                Investor.Rows.Clear()
                If (Me.IsDisposed) Then Exit Sub
                'Investor = CInvestorDetails.SearchInvestorDetail(RowID)

                IDR = CInvestorDetails.SearchInvestorDetail(RowID, Criteria)
                Investor.Load(IDR)
                mdlCommon.ChangeDataReaderDataTable(Investor)
                If MergInvestor.Columns.Contains("RowID") Then
                    MergInvestor.Merge(Investor)
                Else
                    MergInvestor = Investor.Copy()
                End If
                lblTotalInvestor.Text = "Total investors :- " & MergInvestor.Rows.Count
                grdInvestors.DataSource = MergInvestor
                HideGridColumns()

                Application.DoEvents()
                RowID = MergInvestor.Rows(MergInvestor.Rows.Count - 1)("RowID")
                i = i + 3000
                If (Me.IsDisposed) Then Exit Sub
                If _IsStoped = True Then Exit For
            Next
            If _IsStoped = False Then
                If Count > RowID Then
                    Investor.Rows.Clear()
                    IDR = CInvestorDetails.SearchInvestorDetail(RowID, Criteria)
                    Investor.Load(IDR)
                    MergInvestor.Merge(Investor)
                    grdInvestors.DataSource = MergInvestor
                    HideGridColumns()
                    Application.DoEvents()
                End If
            Else
            End If
            btnExport.Visible = True
            btnExport.Enabled = True
            lblTotalInvestor.Text = "Total investors:- " & MergInvestor.Rows.Count
            If (grdInvestors.Rows.Count > 0) Then
                grdInvestors.DisplayLayout.Bands(0).Columns("Investor Name").PerformAutoResize(grdInvestors.Rows.Count)
            End If
            For Each col As UltraGridColumn In Me.grdInvestors.DisplayLayout.Bands(0).Columns
                col.Header.Appearance.BackColor = Color.FromArgb(79, 129, 189)
                'col.PerformAutoResize(grdInvestors.Rows.Count)
            Next
            ShowCheckedGridColumn()
            'column.PerformAutoResize(PerformAutoSizeType.AllRowsInBand, True)
            'grdInvestors.DisplayLayout.AutoFitStyle = AutoFitStyle.ResizeAllColumns
        Catch ex As Exception
            MessageBox.Show(ex.Message)
            'MessageBox.Show(ex.Message)
        Finally
            CInvestorDetails = Nothing
            Investor = Nothing
            MergInvestor = Nothing
            lblTotalInvestor.Visible = True
            txtSearchIn.Enabled = True
            cmbSearchField.Enabled = True
            dv = Nothing
        End Try
    End Sub

    ' <summary>
    ' Select the Investor with Search Condtion
    ' </summary>
    ' <remarks></remarks>

    Private Sub LoadInvestors()
        Dim CInvestorDetails As New cInvestorDetails
        Dim Searchin As Integer
        Dim LookFor As String = ""
        Dim Investor As New DataTable
        Dim IDR As IDataReader = Nothing
        Dim Criteria As Short
        Dim waitDialog As New WaitDialogForm()
        Try
            lblMessage.Visible = False
            Application.DoEvents()
            If (_SearchField <> cmbSearchField.Text.Trim) Then
                _SearchField = cmbSearchField.Text
            End If
            If rdContains.Checked Then
                Criteria = SearchCriteria.Contains
            Else
                Criteria = SearchCriteria.BeginWith
            End If
            Select Case cmbSearchField.SelectedValue.ToLower
                Case "investor name"
                    Searchin = InvestorMenu.Investor
                Case "investor id"
                    Searchin = InvestorMenu.EntityID
                Case "status"
                    Searchin = InvestorMenu.Status
                Case "website"
                    Searchin = InvestorMenu.Website
                Case "principal investor"
                    Searchin = InvestorMenu.PrincipalInvestor
                Case "type"
                    Searchin = InvestorMenu.Type
                Case "style"
                    Searchin = InvestorMenu.Style
                Case "turnover"
                    Searchin = InvestorMenu.Turnover
                Case "city"
                    Searchin = InvestorMenu.City
                Case "country"
                    Searchin = InvestorMenu.Country
                Case "parent"
                    Searchin = InvestorMenu.Parent
                Case "ultimate parent"
                    Searchin = InvestorMenu.UltimateParent
                Case "master type"
                    Searchin = InvestorMenu.MasterType
                Case "activist"
                    Searchin = InvestorMenu.Activist
                Case "last report date"
                    Searchin = InvestorMenu.LastReportDate
                Case "equity assets"
                    Searchin = InvestorMenu.EquityAssets
                Case "street1"
                    Searchin = InvestorMenu.Street1
                Case "street2"
                    Searchin = InvestorMenu.Street2
                Case "state"
                    Searchin = InvestorMenu.State
                Case "region"
                    Searchin = InvestorMenu.Region
                Case "mobile"
                    Searchin = InvestorMenu.Mobile
                Case "telephone"
                    Searchin = InvestorMenu.Telephone
                Case "ext"
                    Searchin = InvestorMenu.Ext
                Case "fax"
                    Searchin = InvestorMenu.Fax
                Case "fax2"
                    Searchin = InvestorMenu.Fax2
                Case "email"
                    Searchin = InvestorMenu.Email
            End Select

            LookFor = txtSearchIn.Text.Trim
            If LookFor = String.Empty Then
                If rdAll.Checked = False Then
                    _OnLoad = True
                    rdAll.Checked = True
                    _OnLoad = False
                End If
            Else
                If rdAll.Checked Then
                    LookFor = ""
                    SetTxtSearchText()
                    rdAll.Focus()
                End If
            End If
            If rdAll.Checked And LookFor = String.Empty Then
                Searchin = InvestorMenu.Investor
            End If
            Application.DoEvents()
            pnlButton.Enabled = False
            waitDialog.Show()
            IDR = CInvestorDetails.SearchInvestorDetail(Searchin, LookFor.Replace("'", "''").Replace("_", "[_]").Replace("%", "[%]"), Criteria)
            Investor.Load(IDR)
            mdlCommon.ChangeDataReaderDataTable(Investor)
            If CommonCLL.CheckEmptyDataTable(Investor) Then
                grdInvestors.DataSource = New DataTable
                MessageBox.Show(MessageManager.GetMessage("NORECORD"), mstrMsgBoxCaption, MessageBoxButtons.OK, MessageBoxIcon.Information)
                lblTotalInvestor.Text = "Total investors:- 0"
            Else
                grdInvestors.DataSource = Investor
                HideGridColumns()
                lblTotalInvestor.Text = "Total investors:- " & Investor.Rows.Count
                DefaultDisableCheckedColumns()
                ShowCheckedGridColumn()
                DisableButtonEditDelete(True)
                grdInvestors.DisplayLayout.Rows.Band.Columns("Investor Name").PerformAutoResize()
                grdInvestors.DisplayLayout.Rows.Band.Columns("Principal Investor").PerformAutoResize()
            End If
            pnlButton.Enabled = True

        Catch ex As Exception
            MessageBox.Show(ex.Message)
        Finally
            IDR = Nothing
            Investor = Nothing
            lblTotalInvestor.Visible = True
            waitDialog.Close()
            pnlButton.Enabled = True
        End Try
    End Sub


    ''' <summary>
    ''' Hide the columns 
    ''' </summary>
    ''' <remarks></remarks>

    Public Sub HideGridColumns()
        Try
            With grdInvestors
                If .DisplayLayout.Bands(0).Columns.Exists("investorid") Then
                    .DisplayLayout.Bands(0).Columns("investorid").Hidden = True
                End If

                If .DisplayLayout.Bands(0).Columns.Exists("Type") Then
                    .DisplayLayout.Bands(0).Columns("Type").Hidden = True
                End If

                If .DisplayLayout.Bands(0).Columns.Exists("Principal Investor") Then
                    .DisplayLayout.Bands(0).Columns("Principal Investor").Hidden = True
                End If

                If .DisplayLayout.Bands(0).Columns.Exists("Style") Then
                    .DisplayLayout.Bands(0).Columns("Style").Hidden = True
                End If

                If .DisplayLayout.Bands(0).Columns.Exists("Turnover") Then
                    .DisplayLayout.Bands(0).Columns("Turnover").Hidden = True
                End If

                If .DisplayLayout.Bands(0).Columns.Exists("City") Then
                    .DisplayLayout.Bands(0).Columns("City").Hidden = True
                End If
                If .DisplayLayout.Bands(0).Columns.Exists("Country") Then
                    .DisplayLayout.Bands(0).Columns("Country").Hidden = True
                End If
                If .DisplayLayout.Bands(0).Columns.Exists("IsFormOpend") Then
                    .DisplayLayout.Bands(0).Columns("IsFormOpend").Hidden = True
                End If

                If .DisplayLayout.Bands(0).Columns.Exists("InvestorID") Then
                    .DisplayLayout.Bands(0).Columns("InvestorID").Hidden = True
                End If

                If .DisplayLayout.Bands(0).Columns.Exists("InvEntityId") Then
                    .DisplayLayout.Bands(0).Columns("InvEntityId").Hidden = True
                End If

                If .DisplayLayout.Bands(0).Columns.Exists("RowID") Then
                    .DisplayLayout.Bands(0).Columns("RowID").Hidden = True
                End If

                If .DisplayLayout.Bands(0).Columns.Exists("Activist") Then
                    .DisplayLayout.Bands(0).Columns("Activist").Hidden = True
                End If

                If .DisplayLayout.Bands(0).Columns.Exists("Master Type") Then
                    .DisplayLayout.Bands(0).Columns("Master Type").Hidden = True
                End If

                If .DisplayLayout.Bands(0).Columns.Exists("Status ID") Then
                    .DisplayLayout.Bands(0).Columns("Status ID").Hidden = True
                End If

                If .DisplayLayout.Bands(0).Columns.Exists("Parent") Then
                    .DisplayLayout.Bands(0).Columns("Parent").Hidden = True
                End If

                If .DisplayLayout.Bands(0).Columns.Exists("Ultimate Parent") Then
                    .DisplayLayout.Bands(0).Columns("Ultimate Parent").Hidden = True
                End If

                If .DisplayLayout.Bands(0).Columns.Exists("CurrentDate") Then
                    .DisplayLayout.Bands(0).Columns("CurrentDate").Hidden = True
                End If

                If .DisplayLayout.Bands(0).Columns.Exists("Equity Assets") Then
                    .DisplayLayout.Bands(0).Columns("Equity Assets").Hidden = True
                End If

                If .DisplayLayout.Bands(0).Columns.Exists("WebSite") Then
                    .DisplayLayout.Bands(0).Columns("WebSite").Hidden = True
                End If

                If .DisplayLayout.Bands(0).Columns.Exists("Street1") Then
                    .DisplayLayout.Bands(0).Columns("Street1").Hidden = True
                End If

                If .DisplayLayout.Bands(0).Columns.Exists("Street2") Then
                    .DisplayLayout.Bands(0).Columns("Street2").Hidden = True
                End If

                If .DisplayLayout.Bands(0).Columns.Exists("PostalCode") Then
                    .DisplayLayout.Bands(0).Columns("PostalCode").Hidden = True
                End If

                If .DisplayLayout.Bands(0).Columns.Exists("Postal Code") Then
                    .DisplayLayout.Bands(0).Columns("Postal Code").Hidden = True
                End If

                If .DisplayLayout.Bands(0).Columns.Exists("Region") Then
                    .DisplayLayout.Bands(0).Columns("Region").Hidden = True
                End If

                If .DisplayLayout.Bands(0).Columns.Exists("EmailAddress") Then
                    .DisplayLayout.Bands(0).Columns("EmailAddress").Hidden = True
                End If

                If .DisplayLayout.Bands(0).Columns.Exists("Primary") Then
                    .DisplayLayout.Bands(0).Columns("Primary").Hidden = True
                End If

                If .DisplayLayout.Bands(0).Columns.Exists("Alternate") Then
                    .DisplayLayout.Bands(0).Columns("Alternate").Hidden = True
                End If

                If .DisplayLayout.Bands(0).Columns.Exists("Telephone") Then
                    .DisplayLayout.Bands(0).Columns("Telephone").Hidden = True
                End If

                If .DisplayLayout.Bands(0).Columns.Exists("Mobile") Then
                    .DisplayLayout.Bands(0).Columns("Mobile").Hidden = True
                End If

                If .DisplayLayout.Bands(0).Columns.Exists("Fax") Then
                    .DisplayLayout.Bands(0).Columns("Fax").Hidden = True
                End If

                If .DisplayLayout.Bands(0).Columns.Exists("Fax 2") Then
                    .DisplayLayout.Bands(0).Columns("Fax 2").Hidden = True
                End If

                If .DisplayLayout.Bands(0).Columns.Exists("Telephone") Then
                    .DisplayLayout.Bands(0).Columns("Telephone").Hidden = True
                End If

                If .DisplayLayout.Bands(0).Columns.Exists("Mobile") Then
                    .DisplayLayout.Bands(0).Columns("Mobile").Hidden = True
                End If

                If .DisplayLayout.Bands(0).Columns.Exists("Extension") Then
                    .DisplayLayout.Bands(0).Columns("Extension").Hidden = True
                End If

                If .DisplayLayout.Bands(0).Columns.Exists("Email") Then
                    .DisplayLayout.Bands(0).Columns("Email").Hidden = True
                End If

                If .DisplayLayout.Bands(0).Columns.Exists("State") Then
                    .DisplayLayout.Bands(0).Columns("State").Hidden = True
                End If

                If .DisplayLayout.Bands(0).Columns.Exists("Last Report Date") Then
                    .DisplayLayout.Bands(0).Columns("Last Report Date").Hidden = True
                End If

            End With
        Catch ex As Exception
            Throw ex
        End Try
    End Sub

    Private Sub CheckSelectedField(ByVal text As String)
        For Each ctrl As Control In CType(pnlCBContainer.Controls(0), Misc.UltraPanelClientArea).Controls
            If DirectCast(ctrl, UltraCheckEditor).Text = text Then
                DirectCast(ctrl, UltraCheckEditor).Checked = True
            End If

        Next
    End Sub

    Public Sub ShowCheckedGridColumn()
        Try
            With grdInvestors
                If uchkStatus.Checked Then
                    .DisplayLayout.Bands(0).Columns("Status").Hidden = False
                    .DisplayLayout.Bands(0).Columns("Status").PerformAutoResize()
                Else

                    .DisplayLayout.Bands(0).Columns("Status").Hidden = True
                End If


                If cmbSearchField.SelectedValue = chkInvestorID.Text Or chkInvestorID.Checked Then
                    If Not chkInvestorID.Checked Then
                        chkInvestorID.Checked = True
                    End If
                    .DisplayLayout.Bands(0).Columns("Investor ID").Hidden = False
                    .DisplayLayout.Bands(0).Columns("Investor ID").PerformAutoResize()

                Else
                    .DisplayLayout.Bands(0).Columns("Investor ID").Hidden = True
                End If

                If uchkInvestorName.Checked Then
                    .DisplayLayout.Bands(0).Columns("Investor Name").Hidden = False
                    .DisplayLayout.Bands(0).Columns("Investor Name").PerformAutoResize()

                Else
                    .DisplayLayout.Bands(0).Columns("Investor Name").Hidden = True
                End If

                If cmbSearchField.SelectedValue = chkWebsite.Text Or chkWebsite.Checked Then
                    If Not chkWebsite.Checked Then
                        chkWebsite.Checked = True
                    End If
                    .DisplayLayout.Bands(0).Columns("WebSite").Hidden = False
                    .DisplayLayout.Bands(0).Columns("WebSite").PerformAutoResize()

                Else
                    .DisplayLayout.Bands(0).Columns("WebSite").Hidden = True
                End If

                If cmbSearchField.SelectedValue = chkPrincipalInvestor.Text Or chkPrincipalInvestor.Checked Then
                    If Not chkPrincipalInvestor.Checked Then
                        chkPrincipalInvestor.Checked = True
                    End If
                    .DisplayLayout.Bands(0).Columns("Principal Investor").Hidden = False
                    .DisplayLayout.Bands(0).Columns("Principal Investor").PerformAutoResize()

                Else
                    .DisplayLayout.Bands(0).Columns("Principal Investor").Hidden = True
                End If

                If cmbSearchField.SelectedValue = chkType.Text Or chkType.Checked Then
                    If Not chkType.Checked Then
                        chkType.Checked = True
                    End If
                    .DisplayLayout.Bands(0).Columns("Type").Hidden = False
                    .DisplayLayout.Bands(0).Columns("Type").PerformAutoResize()

                Else
                    .DisplayLayout.Bands(0).Columns("Type").Hidden = True
                End If

                If cmbSearchField.SelectedValue = chkStyle.Text Or chkStyle.Checked Then
                    If Not chkStyle.Checked Then
                        chkStyle.Checked = True
                    End If
                    .DisplayLayout.Bands(0).Columns("Style").Hidden = False
                    .DisplayLayout.Bands(0).Columns("Style").PerformAutoResize()

                Else
                    .DisplayLayout.Bands(0).Columns("Style").Hidden = True
                End If

                If cmbSearchField.SelectedValue = chkTurnover.Text Or chkTurnover.Checked Then
                    If Not chkTurnover.Checked Then
                        chkTurnover.Checked = True
                    End If
                    chkTurnover.Checked = True
                    .DisplayLayout.Bands(0).Columns("Turnover").Hidden = False
                    .DisplayLayout.Bands(0).Columns("Turnover").PerformAutoResize()

                Else
                    .DisplayLayout.Bands(0).Columns("Turnover").Hidden = True
                End If

                If cmbSearchField.SelectedValue = chkCity.Text Or chkCity.Checked Then
                    If Not chkCity.Checked Then
                        chkCity.Checked = True
                    End If
                    .DisplayLayout.Bands(0).Columns("City").Hidden = False
                    .DisplayLayout.Bands(0).Columns("City").PerformAutoResize()

                Else
                    .DisplayLayout.Bands(0).Columns("City").Hidden = True
                End If

                If cmbSearchField.SelectedValue = chkCountry.Text Or chkCountry.Checked Then
                    If Not chkCountry.Checked Then
                        chkCountry.Checked = True
                    End If
                    .DisplayLayout.Bands(0).Columns("Country").Hidden = False
                    .DisplayLayout.Bands(0).Columns("Country").PerformAutoResize()

                Else
                    .DisplayLayout.Bands(0).Columns("Country").Hidden = True
                End If

                If cmbSearchField.SelectedValue = chkParent.Text Or chkParent.Checked Then
                    If Not chkParent.Checked Then
                        chkParent.Checked = True
                    End If
                    .DisplayLayout.Bands(0).Columns("Parent").Hidden = False
                    .DisplayLayout.Bands(0).Columns("Parent").PerformAutoResize()

                Else
                    .DisplayLayout.Bands(0).Columns("Parent").Hidden = True
                End If

                If cmbSearchField.SelectedValue = chkUltimateParent.Text Or chkUltimateParent.Checked Then
                    If Not chkUltimateParent.Checked Then
                        chkUltimateParent.Checked = True
                    End If
                    .DisplayLayout.Bands(0).Columns("Ultimate Parent").Hidden = False
                    .DisplayLayout.Bands(0).Columns("Ultimate Parent").PerformAutoResize()

                Else
                    .DisplayLayout.Bands(0).Columns("Ultimate Parent").Hidden = True
                End If

                If cmbSearchField.SelectedValue = chkMasterType.Text Or chkMasterType.Checked Then
                    If Not chkMasterType.Checked Then
                        chkMasterType.Checked = True
                    End If
                    .DisplayLayout.Bands(0).Columns("Master Type").Hidden = False
                    .DisplayLayout.Bands(0).Columns("Master Type").PerformAutoResize()

                Else
                    .DisplayLayout.Bands(0).Columns("Master Type").Hidden = True
                End If

                If cmbSearchField.SelectedValue = chkLastReportDate.Text Or chkLastReportDate.Checked Then
                    If Not chkLastReportDate.Checked Then
                        chkLastReportDate.Checked = True
                    End If
                    .DisplayLayout.Bands(0).Columns("Last Report Date").Hidden = False
                    .DisplayLayout.Bands(0).Columns("Last Report Date").PerformAutoResize()

                Else
                    .DisplayLayout.Bands(0).Columns("Last Report Date").Hidden = True
                End If

                If cmbSearchField.SelectedValue = chkActivist.Text Or chkActivist.Checked Then
                    If Not chkActivist.Checked Then
                        chkActivist.Checked = True
                    End If
                    .DisplayLayout.Bands(0).Columns("Activist").Hidden = False
                    .DisplayLayout.Bands(0).Columns("Activist").PerformAutoResize()

                Else
                    .DisplayLayout.Bands(0).Columns("Activist").Hidden = True
                End If

                If cmbSearchField.SelectedValue = chkEquityAssets.Text Or chkEquityAssets.Checked Then
                    If Not chkEquityAssets.Checked Then
                        chkEquityAssets.Checked = True
                    End If
                    .DisplayLayout.Bands(0).Columns("Equity Assets").Hidden = False
                    .DisplayLayout.Bands(0).Columns("Equity Assets").PerformAutoResize()

                Else
                    .DisplayLayout.Bands(0).Columns("Equity Assets").Hidden = True
                End If

                If cmbSearchField.SelectedValue = chkStreet1.Text Or chkStreet1.Checked Then
                    If Not chkStreet1.Checked Then
                        chkStreet1.Checked = True
                    End If
                    .DisplayLayout.Bands(0).Columns("Street1").Hidden = False
                    .DisplayLayout.Bands(0).Columns("Street1").PerformAutoResize()

                Else
                    .DisplayLayout.Bands(0).Columns("Street1").Hidden = True
                End If

                If cmbSearchField.SelectedValue = chkStreet2.Text Or chkStreet2.Checked Then
                    If Not chkStreet2.Checked Then
                        chkStreet2.Checked = True
                    End If
                    .DisplayLayout.Bands(0).Columns("Street2").Hidden = False
                    .DisplayLayout.Bands(0).Columns("Street2").PerformAutoResize()

                Else
                    .DisplayLayout.Bands(0).Columns("Street2").Hidden = True
                End If

                If cmbSearchField.SelectedValue = chkState.Text Or chkState.Checked Then
                    If Not chkState.Checked Then
                        chkState.Checked = True
                    End If
                    .DisplayLayout.Bands(0).Columns("State").Hidden = False
                    .DisplayLayout.Bands(0).Columns("State").PerformAutoResize()

                Else
                    .DisplayLayout.Bands(0).Columns("State").Hidden = True
                End If

                If cmbSearchField.SelectedValue = chkRegion.Text Or chkRegion.Checked Then
                    If Not chkRegion.Checked Then
                        chkRegion.Checked = True
                    End If
                    .DisplayLayout.Bands(0).Columns("Region").Hidden = False
                    .DisplayLayout.Bands(0).Columns("Region").PerformAutoResize()

                Else
                    .DisplayLayout.Bands(0).Columns("Region").Hidden = True
                End If

                If cmbSearchField.SelectedValue = chkMobile.Text Or chkMobile.Checked Then
                    If Not chkMobile.Checked Then
                        chkMobile.Checked = True
                    End If
                    .DisplayLayout.Bands(0).Columns("Mobile").Hidden = False
                    .DisplayLayout.Bands(0).Columns("Mobile").PerformAutoResize()

                Else
                    .DisplayLayout.Bands(0).Columns("Mobile").Hidden = True
                End If

                If cmbSearchField.SelectedValue = chkTelephone.Text Or chkTelephone.Checked Then
                    If Not chkTelephone.Checked Then
                        chkTelephone.Checked = True
                    End If
                    .DisplayLayout.Bands(0).Columns("Telephone").Hidden = False
                    .DisplayLayout.Bands(0).Columns("Telephone").PerformAutoResize()

                Else
                    .DisplayLayout.Bands(0).Columns("Telephone").Hidden = True
                End If

                If cmbSearchField.SelectedValue = chkFax.Text Or chkFax.Checked Then
                    If Not chkFax.Checked Then
                        chkFax.Checked = True
                    End If
                    .DisplayLayout.Bands(0).Columns("Fax").Hidden = False
                    .DisplayLayout.Bands(0).Columns("Fax").PerformAutoResize()

                Else
                    .DisplayLayout.Bands(0).Columns("Fax").Hidden = True
                End If

                If cmbSearchField.SelectedValue = chkFax2.Text Or chkFax2.Checked Then
                    If Not chkFax2.Checked Then
                        chkFax2.Checked = True
                    End If
                    .DisplayLayout.Bands(0).Columns("Fax 2").Hidden = False
                    .DisplayLayout.Bands(0).Columns("Fax 2").PerformAutoResize()

                Else
                    .DisplayLayout.Bands(0).Columns("Fax 2").Hidden = True
                End If

                If cmbSearchField.SelectedValue = chkExt.Text Or chkExt.Checked Then
                    If Not chkExt.Checked Then
                        chkExt.Checked = True
                    End If
                    .DisplayLayout.Bands(0).Columns("Extension").Hidden = False
                    .DisplayLayout.Bands(0).Columns("Extension").PerformAutoResize()

                Else
                    .DisplayLayout.Bands(0).Columns("Extension").Hidden = True
                End If
                If cmbSearchField.SelectedValue = chkEmail.Text Or chkEmail.Checked Then
                    If Not chkEmail.Checked Then
                        chkEmail.Checked = True
                    End If
                    .DisplayLayout.Bands(0).Columns("Email").Hidden = False
                    .DisplayLayout.Bands(0).Columns("Email").PerformAutoResize()

                Else
                    .DisplayLayout.Bands(0).Columns("Email").Hidden = True
                End If
                .DisplayLayout.Bands(0).Columns("investorid").Hidden = True
            End With
        Catch ex As Exception
            Throw ex
        End Try
    End Sub

    Public Function IsCheckBoxChecked() As Boolean
        If (chkActivist.Checked Or chkCity.Checked Or chkCountry.Checked Or chkEmail.Checked Or chkEquityAssets.Checked Or chkExt.Checked Or chkFax.Checked _
            Or chkFax2.Checked Or chkInvestorID.Checked Or chkLastReportDate.Checked Or chkMasterType.Checked Or chkMobile.Checked _
            Or chkParent.Checked Or chkPrincipalInvestor.Checked Or chkRegion.Checked Or chkState.Checked Or chkStreet1.Checked Or _
            chkStreet2.Checked Or chkStyle.Checked Or chkTelephone.Checked Or chkTurnover.Checked Or chkType.Checked Or chkUltimateParent.Checked) Then
            Return False
        Else
            Return True
        End If
    End Function

    Public Sub ShowDefaultSelectedColumns()
        uchkStatus.Checked = True
        uchkInvestorName.Checked = True
        chkPrincipalInvestor.Checked = True
        chkType.Checked = True
        chkStyle.Checked = True
        chkTurnover.Checked = True
        chkCity.Checked = True
        chkCountry.Checked = True
    End Sub

    Public Sub DefaultDisableCheckedColumns()
        uchkStatus.Enabled = False
        uchkInvestorName.Enabled = False
        uchkInvestorName.Checked = True
        uchkStatus.Checked = True
        uchkStatus.ForeColor = Color.White
        uchkInvestorName.ForeColor = Color.White
    End Sub

    ''' <summary>
    ''' Calls the method to get Investors
    ''' </summary>
    ''' <remarks></remarks>

    Private Sub SeachInvestor()
        If (Me.IsDisposed) Then
            Exit Sub
        End If
        'If txtSearchIn.Text.Trim = "" Then
        '    Dim searchText As String
        '    searchText = txtSearchIn.Text
        '    If (_SearchField <> cmbSearchField.SelectedValue.Trim) Then
        '        cmbSearchField.SelectedText = _SearchField
        '    End If
        '    _IsStoped = False
        '    'LoadInvestorSearch()
        '    'rdSearchResult.Checked = True
        '    'txtSearchIn.Text = searchText
        '    'Exit Sub
        'End If
        '_IsStoped = False
        'If Validations() Then Exit Sub
        LoadInvestors()
    End Sub

    ''' <summary>
    ''' Shows the menu 
    ''' </summary>
    ''' <param name="mousePoint"></param>
    ''' <remarks></remarks>

    Private Sub ShowSearchMenu(ByVal mousePoint As Point)
        cmsSearch.Show(lblSearchGrid, mousePoint)
    End Sub

    ''' <summary>
    ''' validates the manditory field
    ''' </summary>
    ''' <returns></returns>
    ''' <remarks></remarks>

    Private Function Validations() As Boolean
        Try
            If cmbSearchField.Text.Trim = "" Then
                MessageBox.Show(MessageManager.GetMessage("NOFIELDSELECTED"), mstrMsgBoxCaption, MessageBoxButtons.OK, MessageBoxIcon.Information)
                cmbSearchField.Focus()
                Return True
            End If

            Return False
        Catch ex As Exception
            Throw ex
        End Try
    End Function
#End Region

#Region "Events"

    Private Sub llbSearch_MouseDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs)
        Dim mousePoint As Point = New Point(e.X, e.Y)
        ShowSearchMenu(mousePoint)
    End Sub

    Private Sub cmsSearch_ItemClicked(ByVal sender As System.Object, ByVal e As System.Windows.Forms.ToolStripItemClickedEventArgs)
        cmbSearchField.Text = e.ClickedItem.Text
        _SearchField = cmbSearchField.SelectedValue
        txtSearchIn.Focus()
    End Sub

    Private Sub grdInvestors_DoubleClickCell(ByVal sender As System.Object, ByVal e As Infragistics.Win.UltraWinGrid.DoubleClickCellEventArgs)

        EditInvestor()
    End Sub
    Private Function IsChildFormOpened() As Boolean
        For lmFomrs As Integer = 0 To Application.OpenForms.Count - 1
            If Application.OpenForms(lmFomrs).Name = "frmAddModifyInvestor" Then
                Application.OpenForms(lmFomrs).BringToFront()
                Return False
            End If
        Next
        Return True
    End Function

    Public Sub EditInvestor()
        Dim objinvestor As cAddModifyInvestor = Nothing

        For lmFomrs As Integer = 0 To Application.OpenForms.Count - 1
            If Application.OpenForms(lmFomrs).Name = "frmAddModifyInvestor" Then
                If CType(Application.OpenForms(lmFomrs), frmAddModifyInvestor).WindowState = FormWindowState.Minimized Then
                    CType(Application.OpenForms(lmFomrs), frmAddModifyInvestor).WindowState = FormWindowState.Normal
                End If
                If (FocusTheExistingInstanceOfForm(grdInvestors.ActiveRow.Cells("InvestorID").Value, _
                                                   "frmAddModifyInvestor", CType(Application.OpenForms(lmFomrs), frmAddModifyInvestor).WindowState)) Then
                    Return
                End If
            End If
        Next
        Dim count As Integer
        Try
            objinvestor = New cAddModifyInvestor
            If (CheckRecordExistence("investor", grdInvestors.ActiveRow.Cells("InvestorID").Value.ToString())) Then

                count = (From id In LstModiFiedUserId _
                  Where id = grdInvestors.ActiveRow.Cells("InvestorID").Value Select id).SingleOrDefault
                If (count = 0) Then
                    LstModiFiedUserId.Add(grdInvestors.ActiveRow.Cells("InvestorID").Value.ToString())
                    Dim lfrmAddModifyInvestor As New frmAddModifyInvestor
                    lfrmAddModifyInvestor.InvestorId = grdInvestors.ActiveRow.Cells("InvestorID").Value
                    Dim name As String = grdInvestors.ActiveRow.Cells("Investor Name").Value
                    lfrmAddModifyInvestor.Text = "Crysral - Edit " + name
                    lfrmAddModifyInvestor.StartPosition = FormStartPosition.CenterScreen
                    AddHandler lfrmAddModifyInvestor.CloseUserWindow, AddressOf CloseUserWindow
                    AddHandler lfrmAddModifyInvestor.AddParticularInvestorInGrid, AddressOf AddParticularInvestorInGrid
                    lfrmAddModifyInvestor.Show()
                End If
            Else
                grdInvestors.ActiveRow.Delete(False)
                MessageBox.Show(MessageManager.GetMessage(DBResult.RECORDNOTEXISTS))

            End If
        Catch ex As Exception
            MessageBox.Show(ex.Message)
        Finally
            objinvestor = Nothing
            'DataTable = Nothing
        End Try
    End Sub

    Private Sub btnImport_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnImport.Click
        For lmFomrs As Integer = 0 To Application.OpenForms.Count - 1
            If Application.OpenForms(lmFomrs).Name = "frmUploadInvestor" Then
                If CType(Application.OpenForms(lmFomrs), frmUploadInvestor).WindowState = FormWindowState.Minimized Then
                    CType(Application.OpenForms(lmFomrs), frmUploadInvestor).WindowState = FormWindowState.Normal
                End If
                If (FocusTheExistingInstanceOfForm("frmUploadInvestor", CType(Application.OpenForms(lmFomrs), frmUploadInvestor).WindowState)) Then
                    Return
                End If
            End If
        Next
        Dim lfrmImportInvestors As New frmUploadInvestor
        AddHandler lfrmImportInvestors.LoadImportedInvestor, AddressOf LoadImportedInvestor
        lfrmImportInvestors.ShowDialog()
    End Sub

    Private Sub LoadGridAfterImport(ByVal funds As DataTable)
        grdInvestors.DataSource = funds
        HideGridColumns()
        txtSearchIn.Text = ""
        If (grdInvestors.Rows.Count > 0) Then
            btnDelete.Enabled = True
        End If
        FormatGrid(grdInvestors)
        ShowCheckedGridColumn()
    End Sub

    Public Sub LoadImportedInvestor(ByVal funds As DataTable)
        Try
            If (Me.IsDisposed) Then Exit Sub
            Me.Invoke(New GridBind(AddressOf LoadGridAfterImport), funds)
            Me.Invoke(New ControlVisiblityImportDelegate(AddressOf VisibleControl), funds.Rows.Count)
        Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try
    End Sub

    Private Sub VisibleControl(ByVal Val As Integer)
        lblTotalInvestor.Text = "Total investors:- " & Val
        btnExport.Enabled = True
        txtSearchIn.Enabled = True
        cmbSearchField.Enabled = True
        btnAddInvestor.Enabled = True
        lblMessage.Visible = False
        'btnModifyUser.Enabled = True
    End Sub

    ''' <summary>
    ''' creating the datatable for the grid if it's datasource is nothing
    ''' </summary>
    ''' <remarks></remarks>
    ''' 

    Private Function CreateDatatable() As DataTable
        Dim dt As DataTable = Nothing
        Dim dr As DataRow = Nothing
        Try
            dt = New DataTable
            dt.Columns.Add("investorid", GetType(System.String))
            dt.Columns.Add("Status", GetType(System.String))
            dt.Columns.Add("Investor ID", GetType(System.String))
            dt.Columns.Add("Investor Name", GetType(System.String))
            dt.Columns.Add("WebSite", GetType(System.String))
            dt.Columns.Add("Principal Investor", GetType(System.String))
            dt.Columns.Add("Style", GetType(System.String))
            dt.Columns.Add("Turnover", GetType(System.String))
            dt.Columns.Add("City", GetType(System.String))
            dt.Columns.Add("Country", GetType(System.String))
            dt.Columns.Add("Parent", GetType(System.String))
            dt.Columns.Add("Ultimate Parent", GetType(System.String))
            dt.Columns.Add("Master Type", GetType(System.String))
            dt.Columns.Add("Activist", GetType(System.String))
            dt.Columns.Add("Last Report Date", GetType(System.String))
            dt.Columns.Add("Equity Assets", GetType(System.String))
            dt.Columns.Add("Type", GetType(System.String))
            dt.Columns.Add("Street1", GetType(System.String))
            dt.Columns.Add("Street2", GetType(System.String))
            dt.Columns.Add("State", GetType(System.String))
            dt.Columns.Add("Region", GetType(System.String))
            dt.Columns.Add("Mobile", GetType(System.String))
            dt.Columns.Add("Telephone", GetType(System.String))
            dt.Columns.Add("Extension", GetType(System.String))
            'dt.Columns.Add("IsFormOpened", GetType(System.String))
            dt.Columns.Add("Fax", GetType(System.String))
            dt.Columns.Add("Fax 2", GetType(System.String))
            dt.Columns.Add("Email", GetType(System.String))
            Return dt
        Catch ex As Exception
            If (Not Me.IsDisposed) Then
                MessageBox.Show(ex.Message)
            End If
            Return Nothing
        Finally
            dt = Nothing
        End Try
    End Function

    ''' <summary>
    ''' Adds New record in grid or updating Existing Record in Grid
    ''' </summary>
    ''' <param name="InvestorID"></param>
    ''' <remarks></remarks>
    ''' 

    Public Sub AddParticularInvestorInGrid(ByVal InvestorID As Integer)
        'SeachInvestor()
        If (Me.IsDisposed) Then Exit Sub
        Dim CInvestorDetails As New cInvestorDetails
        Dim dDtFund As New DataTable
        Dim dDtGrdFunds As DataTable
        Dim Dr() As DataRow
        Dim dv As New DataView
        Dim drow As DataRow = Nothing
        Dim IDR As IDataReader = Nothing
        Dim Logmessage As New System.Text.StringBuilder
        Try
            IDR = CInvestorDetails.GetInvestorDetail(InvestorID)
            dDtFund.Load(IDR)
            mdlCommon.ChangeDataReaderDataTable(dDtFund)
            If dDtFund.Rows.Count = 0 Then Exit Sub
            dDtGrdFunds = CType(grdInvestors.DataSource, DataTable)
            If (dDtGrdFunds Is Nothing) Then
                dDtGrdFunds = CreateDatatable()
                drow = dDtGrdFunds.NewRow
                drow("investorid") = dDtFund.Rows(0)("investorid")
                drow("Status") = dDtFund.Rows(0)("Status")
                drow("Investor Id") = dDtFund.Rows(0)("Investor Id")
                drow("Investor Name") = dDtFund.Rows(0)("Investor Name")
                drow("WebSite") = dDtFund.Rows(0)("WebSite")
                drow("Principal Investor") = dDtFund.Rows(0)("Principal Investor")
                drow("Type") = dDtFund.Rows(0)("Type")
                drow("Style") = dDtFund.Rows(0)("Style")
                drow("Turnover") = dDtFund.Rows(0)("Turnover")
                drow("City") = dDtFund.Rows(0)("City")
                drow("State") = dDtFund.Rows(0)("State")
                drow("Country") = dDtFund.Rows(0)("Country")
                drow("Master Type") = dDtFund.Rows(0)("Master Type")
                drow("Ultimate Parent") = dDtFund.Rows(0)("Ultimate Parent")
                drow("Street1") = dDtFund.Rows(0)("Street1")
                drow("Activist") = dDtFund.Rows(0)("Activist")
                drow("Last Report Date") = dDtFund.Rows(0)("Last Report Date")
                drow("Equity Assets") = dDtFund.Rows(0)("Equity Assets")
                drow("Parent") = dDtFund.Rows(0)("Parent")
                drow("Street2") = dDtFund.Rows(0)("Street2")
                drow("Region") = dDtFund.Rows(0)("Region")
                drow("Email") = dDtFund.Rows(0)("Email")
                drow("Fax") = dDtFund.Rows(0)("Fax")
                drow("Fax 2") = dDtFund.Rows(0)("Fax 2")
                drow("Mobile") = dDtFund.Rows(0)("Mobile")
                drow("Telephone") = dDtFund.Rows(0)("Telephone")
                drow("Extension") = dDtFund.Rows(0)("Extension")
                dDtGrdFunds.Rows.Add(drow)
            Else
                If dDtGrdFunds.Rows.Count = 0 Then
                    dDtGrdFunds = CreateDatatable()
                    drow = dDtGrdFunds.NewRow
                    drow("investorid") = dDtFund.Rows(0)("investorid")
                    drow("Status") = dDtFund.Rows(0)("Status")
                    drow("Investor Id") = dDtFund.Rows(0)("Investor Id")
                    drow("Investor Name") = dDtFund.Rows(0)("Investor Name")
                    drow("WebSite") = dDtFund.Rows(0)("WebSite")
                    drow("Principal Investor") = dDtFund.Rows(0)("Principal Investor")
                    drow("Type") = dDtFund.Rows(0)("Type")
                    drow("Style") = dDtFund.Rows(0)("Style")
                    drow("Turnover") = dDtFund.Rows(0)("Turnover")
                    drow("City") = dDtFund.Rows(0)("City")
                    drow("State") = dDtFund.Rows(0)("State")
                    drow("Country") = dDtFund.Rows(0)("Country")
                    drow("Master Type") = dDtFund.Rows(0)("Master Type")
                    drow("Ultimate Parent") = dDtFund.Rows(0)("Ultimate Parent")
                    drow("Street1") = dDtFund.Rows(0)("Street1")
                    drow("Activist") = dDtFund.Rows(0)("Activist")
                    drow("Last Report Date") = dDtFund.Rows(0)("Last Report Date")
                    drow("Equity Assets") = dDtFund.Rows(0)("Equity Assets")
                    drow("Parent") = dDtFund.Rows(0)("Parent")
                    drow("Street2") = dDtFund.Rows(0)("Street2")
                    drow("Region") = dDtFund.Rows(0)("Region")
                    drow("Email") = dDtFund.Rows(0)("Email")
                    drow("Fax") = dDtFund.Rows(0)("Fax")
                    drow("Fax 2") = dDtFund.Rows(0)("Fax 2")
                    drow("Mobile") = dDtFund.Rows(0)("Mobile")
                    drow("Telephone") = dDtFund.Rows(0)("Telephone")
                    drow("Extension") = dDtFund.Rows(0)("Extension")
                    dDtGrdFunds.Rows.Add(drow)
                End If
                Dr = dDtGrdFunds.Select("InvestorID=" + InvestorID.ToString())
                If Dr.Length > 0 Then
                    Dr(0)("investorid") = dDtFund.Rows(0)("investorid")
                    Dr(0)("Status") = dDtFund.Rows(0)("Status")
                    Dr(0)("Investor Id") = dDtFund.Rows(0)("Investor Id")
                    Dr(0)("Investor Name") = dDtFund.Rows(0)("Investor Name")
                    Dr(0)("WebSite") = dDtFund.Rows(0)("WebSite")
                    Dr(0)("Principal Investor") = dDtFund.Rows(0)("Principal Investor")
                    Dr(0)("Type") = dDtFund.Rows(0)("Type")
                    Dr(0)("Style") = dDtFund.Rows(0)("Style")
                    Dr(0)("Turnover") = dDtFund.Rows(0)("Turnover")
                    Dr(0)("City") = dDtFund.Rows(0)("City")
                    Dr(0)("State") = dDtFund.Rows(0)("State")
                    Dr(0)("Country") = dDtFund.Rows(0)("Country")
                    Dr(0)("Master Type") = dDtFund.Rows(0)("Master Type")
                    Dr(0)("Ultimate Parent") = dDtFund.Rows(0)("Ultimate Parent")
                    Dr(0)("Street1") = dDtFund.Rows(0)("Street1")
                    Dr(0)("Activist") = dDtFund.Rows(0)("Activist")
                    Dr(0)("Last Report Date") = dDtFund.Rows(0)("Last Report Date")
                    Dr(0)("Equity Assets") = dDtFund.Rows(0)("Equity Assets")
                    Dr(0)("Parent") = dDtFund.Rows(0)("Parent")
                    Dr(0)("Street2") = dDtFund.Rows(0)("Street2")
                    Dr(0)("Region") = dDtFund.Rows(0)("Region")
                    Dr(0)("Email") = dDtFund.Rows(0)("Email")
                    Dr(0)("Fax") = dDtFund.Rows(0)("Fax")
                    Dr(0)("Fax 2") = dDtFund.Rows(0)("Fax 2")
                    Dr(0)("Mobile") = dDtFund.Rows(0)("Mobile")
                    Dr(0)("Telephone") = dDtFund.Rows(0)("Telephone")
                    Dr(0)("Extension") = dDtFund.Rows(0)("Extension")
                Else
                    dDtGrdFunds.Merge(dDtFund, True, MissingSchemaAction.Ignore)
                End If
            End If
            dv = New DataView(dDtGrdFunds)
            dv.Sort = "[Investor Name] asc"
            grdInvestors.DataSource = dv.ToTable()
            If grdInvestors.Rows.Count = 1 Then
                DefaultDisableCheckedColumns()
            End If
            ShowCheckedGridColumn()
            lblTotalInvestor.Text = "Total investors:- " + grdInvestors.Rows.Count.ToString()
            ' Dim selectedRow As DataRow() = dv.ToTable().Select("InvestorID=" + InvestorID.ToString())
            Dim colRow As UltraGridRow = Me.grdInvestors.Rows.OfType(Of UltraGridRow)().ToList().Find(Function(row) row.Cells("InvestorID").Text.Equals(InvestorID.ToString(), StringComparison.CurrentCultureIgnoreCase))
            grdInvestors.Selected.Rows.Add(colRow)
            grdInvestors.ActiveRow = colRow ' colRow.Activate()
            'grdInvestors.ActiveRow = grdInvestors.Selected.Rows.
        Catch ex As Exception
            If (Not Me.IsDisposed) Then
                'MessageBox.Show(ex.Message)
                MessageBox.Show(ex.Message)
                Logmessage.Append("There is error in GetInvestorByFundID of form findmanagement.")
                Logmessage.Append(Environment.NewLine)
                Logmessage.Append("Error Message - ")
                Logmessage.Append(ex.ToString())
                Me.LogErrorToDatabase(Logmessage.ToString)
            End If
        Finally

            rdSearchResult.Checked = True
            CInvestorDetails = Nothing
            dDtFund = Nothing
            dDtGrdFunds = Nothing
            Dr = Nothing
            If (grdInvestors.Rows.Count > 0) Then
                DisableButtonEditDelete(True)
                lblMessage.Visible = False
            Else
                DisableButtonEditDelete(False)
            End If
        End Try
    End Sub

    Private Sub btnAddInvestor_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAddInvestor.Click ', btnModifyUser.Click

        Dim objinvestor As cAddModifyInvestor = Nothing
        Try
            If (CType(sender, Control).Name = "btnAddInvestor") Then
                For lmFomrs As Integer = 0 To Application.OpenForms.Count - 1
                    If Application.OpenForms(lmFomrs).Name = "frmAddModifyInvestor" Then
                        If CType(Application.OpenForms(lmFomrs), frmAddModifyInvestor).WindowState = FormWindowState.Minimized Then
                            CType(Application.OpenForms(lmFomrs), frmAddModifyInvestor).WindowState = FormWindowState.Maximized
                        End If

                        If (FocusTheExistingInstanceOfForm(0, "frmAddModifyInvestor", CType(Application.OpenForms(lmFomrs), frmAddModifyInvestor).WindowState)) Then
                            Return
                        End If
                    End If
                Next
                Dim lfrmAddModifyInvestor As New frmAddModifyInvestor
                lfrmAddModifyInvestor.Text = "Crystal - Add Investor"
                lfrmAddModifyInvestor.StartPosition = FormStartPosition.CenterScreen
                AddHandler lfrmAddModifyInvestor.AddParticularInvestorInGrid, AddressOf AddParticularInvestorInGrid
                lfrmAddModifyInvestor.txtInvestorName.Focus()
                lfrmAddModifyInvestor.Show()
                Return
            End If

            If (grdInvestors.ActiveRow Is Nothing) Then
                MessageBox.Show(MessageManager.GetMessage("SELECTTHERECORD"), mstrMsgBoxCaption, MessageBoxButtons.OK, MessageBoxIcon.Information)
                Return
            End If
            If (grdInvestors.ActiveRow.Cells Is Nothing) Then
                MessageBox.Show(MessageManager.GetMessage("SELECTTHERECORD"), mstrMsgBoxCaption, MessageBoxButtons.OK, MessageBoxIcon.Information)
                Return
            End If
            If (grdInvestors.Selected.Rows.Count > 1) Then
                MessageBox.Show(MessageManager.GetMessage("SELECTONERECORD"), mstrMsgBoxCaption, MessageBoxButtons.OK, MessageBoxIcon.Information)
                Return
            End If
            objinvestor = New cAddModifyInvestor

            If (CheckRecordExistence("investor", grdInvestors.ActiveRow.Cells("investorid").Value.ToString())) Then
                Dim Count = (From ID In LstModiFiedUserId _
                     Where ID = grdInvestors.ActiveRow.Cells("investorid").Value _
                     Select ID).Count
                If Count = 0 Then
                    LstModiFiedUserId.Add(grdInvestors.ActiveRow.Cells("investorid").Value)
                    Dim lfrmAddModifyInvestor As New frmAddModifyInvestor
                    lfrmAddModifyInvestor.InvestorId = grdInvestors.ActiveRow.Cells("InvestorID").Value
                    lfrmAddModifyInvestor.Text = "Modify Investor"
                    ' lfrmAddModifyInvestor.btnModify.Enabled = False
                    lfrmAddModifyInvestor.Text = "Cancel Chan&ges"
                    lfrmAddModifyInvestor.StartPosition = FormStartPosition.CenterScreen
                    AddHandler lfrmAddModifyInvestor.CloseUserWindow, AddressOf CloseUserWindow
                    grdInvestors.ActiveRow.Cells("IsFormOpend").Value = True
                    AddHandler lfrmAddModifyInvestor.AddParticularInvestorInGrid, AddressOf AddParticularInvestorInGrid
                    lfrmAddModifyInvestor.Show()
                End If
            Else
                grdInvestors.ActiveRow.Delete(False)
                MessageBox.Show(MessageManager.GetMessage("RECORDNOTEXISTS"), mstrMsgBoxCaption, MessageBoxButtons.OK, MessageBoxIcon.Information)
            End If
        Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try
    End Sub

    Public Sub CloseUserWindow(ByVal InvestorID As Integer)
        ' If grdInvestors.ActiveRow Is Nothing Then Exit Sub
        LstModiFiedUserId.Remove(InvestorID)

    End Sub

    Private Sub btnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExit.Click
        _Thread = Nothing
        Me.Close()
    End Sub

    Private Sub btnExport_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExport.Click
        Dim Dlgsave As New SaveFileDialog

        Try
            If grdInvestors.Rows Is Nothing Then Exit Sub

            If Not grdInvestors.Rows.Count > 0 Then Exit Sub

            Dim fileName As String = "Investors - " + DateTime.Now.ToString()
            fileName = fileName.Replace(":", "_").Replace("/", "_")
            Dim dialog As New SaveFileDialog
            With dialog
                .FileName = fileName
                .InitialDirectory = "C:\\"
                .Filter = "Excel (2007-2010 format)(*.xlsx)|*.xlsx|Excel (97-2003 format)(*.xls)|*.xls"
                .DefaultExt = ".xlsx"
            End With
            Dim showDialog As New DialogResult
            showDialog = dialog.ShowDialog()
            If showDialog = DialogResult.OK Then
                lblMessage.Text = "Please wait..."
                lblMessage.Visible = True
                pnlButton.Enabled = False
                Dim strExtension As String = System.IO.Path.GetExtension(dialog.FileName)
                Dim ExpToExcel As New UltraGridExcelExporter

                Dim selectedformat As WorkbookFormat

                If strExtension = ".xlsx" Then
                    selectedformat = WorkbookFormat.Excel2007
                Else
                    selectedformat = WorkbookFormat.Excel97To2003
                End If
                Dim ExcWorkbook As New Workbook(selectedformat, WorkbookPaletteMode.CustomPalette)
                Dim lobjws As Worksheet = ExcWorkbook.Worksheets.Add("Investor")
                ExpToExcel.Export(grdInvestors, lobjws, 0, 0)
                ExcWorkbook.Save(dialog.FileName)
                MessageBox.Show(MessageManager.GetMessage("EXCELFILECREATED"), "Export", MessageBoxButtons.OK, MessageBoxIcon.Information)
                lblMessage.Visible = False
                pnlButton.Enabled = True
            End If

        Catch ex As Exception
            MessageBox.Show(ex.Message, mstrMsgBoxCaption, MessageBoxButtons.OK, MessageBoxIcon.Information)
        Finally
            lblMessage.Visible = False
            pnlButton.Enabled = True
            Dlgsave = Nothing
        End Try


    End Sub

    ''' <summary>
    ''' Deletes Investor From database
    ''' </summary>
    ''' <remarks></remarks>
    ''' 

    Public Sub raiseeventfordelete(ByVal dt As DataTable, ByVal isDeleted As Boolean)
        'Me.IsAccessible = True
        If (Me.IsDisposed) Then Exit Sub
        Dim dDtGrdFunds As DataTable
        Dim indexRow As Integer
        dDtGrdFunds = CType(grdInvestors.DataSource, DataTable)
        For Each row As DataRow In dt.Rows
            If isDeleted Then
                indexRow = FindRowIndex(dDtGrdFunds, "InvestorID", row(0).ToString())
                If indexRow > -1 Then
                    dDtGrdFunds.Rows(indexRow).Delete()
                End If
            Else
                indexRow = FindRowIndex(dDtGrdFunds, "InvestorID", row(0).ToString())
                dDtGrdFunds.Rows(indexRow)("Status") = "Delete"
            End If
        Next
        Dim dv As New DataView(dDtGrdFunds)
        dv.Sort = "[Investor Name] asc"
        grdInvestors.DataSource = dv.ToTable()
        lblTotalInvestor.Text = "Total Investors:- " + grdInvestors.Rows.Count.ToString()

    End Sub

    Private Sub btnDelete_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDelete.Click
        Dim InvestorID As String = ""
        Dim delete As DeleteInvestor

        For lmFomrs As Integer = 0 To Application.OpenForms.Count - 1
            If Application.OpenForms(lmFomrs).Name = "DeleteInvestor" Then
                If CType(Application.OpenForms(lmFomrs), DeleteInvestor).WindowState = FormWindowState.Minimized Then
                    CType(Application.OpenForms(lmFomrs), DeleteInvestor).WindowState = FormWindowState.Maximized
                End If

                If (FocusTheExistingInstanceOfForm("DeleteInvestor", CType(Application.OpenForms(lmFomrs), DeleteInvestor).WindowState)) Then
                    Return
                End If
            End If
        Next

        Try
            If (grdInvestors.ActiveRow Is Nothing) Then
                MessageBox.Show(MessageManager.GetMessage("SELECTTHERECORD"), mstrMsgBoxCaption, MessageBoxButtons.OK, MessageBoxIcon.Information)
                Exit Sub
            Else
                grdInvestors.Selected.Rows.Add(grdInvestors.ActiveRow)
            End If
            For i As Integer = 0 To grdInvestors.Selected.Rows.Count - 1
                If i = grdInvestors.Selected.Rows.Count - 1 Then
                    InvestorID += grdInvestors.Selected.Rows(i).Cells("investorid").Value.ToString()
                Else
                    InvestorID += grdInvestors.Selected.Rows(i).Cells("investorid").Value.ToString() + ","
                End If
            Next

            Dim d As DataTable = grdInvestors.DataSource
            Dim dv As New DataView(d)
            dv.RowFilter = "[investorid] in( " & InvestorID & ")"
            'dv.RowFilter = "[Investor ID] in('" & InvestorID & "')"
            delete = New DeleteInvestor(dv.ToTable)

            AddHandler delete.deleteInvestor, AddressOf raiseeventfordelete
            delete.ShowDialog()
        Catch ex As Exception
            MessageBox.Show(ex.Message)
        Finally
            InvestorID = Nothing
        End Try
    End Sub

    Private Sub frmInvestorManagement_FormClosed(ByVal sender As System.Object, ByVal e As System.Windows.Forms.FormClosedEventArgs) Handles MyBase.FormClosed
        Try
            _IsStoped = True
            _IsThreadAborted = True
            If Not _Thread Is Nothing Then
                If _Thread.IsAlive Then
                    If _Thread.ThreadState = 68 Then
                        _Thread.Resume()
                    End If
                    _Thread.Abort()
                    _Thread.Join()
                End If
            End If
            _IsThreadAborted = True
            'frmInvSearch = Nothing
            _Thread = Nothing
            Me.Dispose()
        Catch ex As Exception
        Finally
            _Thread = Nothing
        End Try
    End Sub

#End Region

#Region "Events"

    Private Sub btnReset_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
        cmbSearchField.Text = "Investor Name"
        _SearchField = "Investor Name"
        txtSearchIn.Text = ""
        _IsStoped = False
        txtSearchIn.Focus()
    End Sub

    Private Sub frmInvestorManagement_Resize(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Resize
        For lmFomrs As Integer = 0 To Application.OpenForms.Count - 1
            If Application.OpenForms(lmFomrs).Name = "frmInvestorManagement" Then
                If (Me.WindowState = FormWindowState.Normal) Then
                    CType(Application.OpenForms(lmFomrs), frmInvestorManagement).WindowState = Me.WindowState
                End If
                If (Me.WindowState = FormWindowState.Maximized) Then
                    CType(Application.OpenForms(lmFomrs), frmInvestorManagement).WindowState = Me.WindowState
                End If
            End If
        Next
    End Sub

    Private Sub cmbSearchField_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmbSearchField.SelectedIndexChanged
        If cmbSearchField.SelectedValue = _NullField Then
            MessageBox.Show("Please select valid search field.", "Crystal", MessageBoxButtons.OK, MessageBoxIcon.Information)
            cmbSearchField.Text = "Investor Name"
            Return
        End If
        _SearchField = cmbSearchField.SelectedValue
        SetTxtSearchText()
        CheckSelectedField(_SearchField)
    End Sub

    Private Sub SetTxtSearchText()
        If cmbSearchField.SelectedValue = "Last Report Date" Then
            txtSearchIn.Text = MessageManager.GetMessage("DEFAULTDATEFORMAT").Trim
        Else
            If txtSearchIn.Text = String.Empty Or txtSearchIn.Text = MessageManager.GetMessage("DEFAULTDATEFORMAT").Trim Then
                txtSearchIn.Text = MessageManager.GetMessage("DEFAULTSEARCHTEXT").Trim
            End If
        End If
    End Sub

    Private Sub txtSearchIn_Enter(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtSearchIn.Enter
        If txtSearchIn.Text.Trim = MessageManager.GetMessage("DEFAULTSEARCHTEXT").Trim Or txtSearchIn.Text.Trim = MessageManager.GetMessage("DEFAULTDATEFORMAT").Trim Then
            txtSearchIn.Text = String.Empty
        End If
    End Sub

    Private Sub txtSearchIn_KeyDown1(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles txtSearchIn.KeyDown
        If cmbSearchField.SelectedValue = "Equity Assets" Then
            If e.KeyValue > 48 And e.KeyValue < 57 Or (e.Control And e.KeyCode = Keys.V) Or (Keys.OemMinus) Or (e.Shift And Keys.Oem3) Or _
                (e.Shift And Keys.D6) Then

            Else
                MessageBox.Show("Please enter valid value.", "Crystal", MessageBoxButtons.OK, MessageBoxIcon.Information)
            End If
            'If txtSearchIn.Text.Length > 0 Then
            '    If Not IsNumeric(txtSearchIn.Text) Then
            '        MessageBox.Show("Please enter numeric values.", "Crystal", MessageBoxButtons.OK, MessageBoxIcon.Information)
            '        txtSearchIn.Text = String.Empty
            '        Return
            '    End If
            '    Dim assetValue As New Int64
            '    assetValue = Convert.ToInt64(txtSearchIn.Text)
            '    If assetValue > _BigInt Or txtSearchIn.Text.Length > 19 Then
            '        MessageBox.Show("Please enter valid equity assets.", "Crystal", MessageBoxButtons.OK, MessageBoxIcon.Information)
            '        Return
            '    End If
            'End If
        End If
        If e.KeyCode = Keys.Enter Then
            If cmbSearchField.SelectedValue = "Last Report Date" Then
                If txtSearchIn.Text.Trim().Length < 3 Then  'Or txtSearchIn.Text.Trim().Length > 8
                    ShowMessage("Please type date in MMM and/or YYYY format.", MessageBoxIcons.Information)
                    Return
                ElseIf txtSearchIn.Text.Trim.Length = 3 Then
                    If IsNumeric(txtSearchIn.Text) Then
                        ShowMessage("Please type date in MMM and/or YYYY format.", MessageBoxIcons.Information)
                        Return
                    End If
                End If

            End If
            If txtSearchIn.Text.Trim <> String.Empty Then
                rdSearchResult.Checked = True
            End If
            SeachInvestor()

        End If

    End Sub

    Private Sub txtSearchIn_Leave(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtSearchIn.Leave
        If txtSearchIn.Text.Trim = String.Empty Then
            If cmbSearchField.SelectedValue = "Last Report Date" Then
                txtSearchIn.Text = MessageManager.GetMessage("DEFAULTDATEFORMAT").Trim
            Else
                txtSearchIn.Text = MessageManager.GetMessage("DEFAULTSEARCHTEXT").Trim
            End If
        End If
    End Sub

    Private Sub GetTooltip(ByVal control As Control, ByVal tooltip As String)
        ToolTip2.SetToolTip(control, ToolTipManager.GetToolTip(tooltip))
    End Sub

    Private Sub btnAddInvestor_MouseHover(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnAddInvestor.MouseHover
        GetTooltip(btnAddInvestor, "ADDNEWINVESTOR")
    End Sub

    Private Sub btnExport_MouseHover(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnExport.MouseHover
        GetTooltip(btnExport, "EXPORTTOEXCEL")
    End Sub

    Private Sub btnImport_MouseHover(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnImport.MouseHover
        GetTooltip(btnImport, "IMPORTFROMEXCEL")
    End Sub

    Private Sub uchkStatus_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles uchkStatus.CheckedChanged
        If grdInvestors.Rows.Count > 0 Then
            If uchkStatus.Checked Then
                grdInvestors.DisplayLayout.Bands(0).Columns("Status").Hidden = False
            Else
                grdInvestors.DisplayLayout.Bands(0).Columns("Status").Hidden = True
            End If
        End If
    End Sub

    Private Sub chkInvestorID_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles chkInvestorID.CheckedChanged
        CheckBoxChangeSearchField()
        If grdInvestors.Rows.Count > 0 Then
            If chkInvestorID.Checked Then
                grdInvestors.DisplayLayout.Bands(0).Columns("Investor ID").Hidden = False
            Else
                grdInvestors.DisplayLayout.Bands(0).Columns("Investor ID").Hidden = True
            End If
        End If
    End Sub

    Private Sub uchkInvestorName_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles uchkInvestorName.CheckedChanged
        If grdInvestors.Rows.Count > 0 Then
            If uchkStatus.Checked Then
                grdInvestors.DisplayLayout.Bands(0).Columns("Investor Name").Hidden = False
            Else
                grdInvestors.DisplayLayout.Bands(0).Columns("Investor Name").Hidden = True
            End If
        End If
    End Sub

    Private Sub chkWebsite_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles chkWebsite.CheckedChanged
        CheckBoxChangeSearchField()
        If grdInvestors.Rows.Count > 0 Then
            If chkWebsite.Checked Then
                grdInvestors.DisplayLayout.Bands(0).Columns("Website").Hidden = False
            Else
                grdInvestors.DisplayLayout.Bands(0).Columns("Website").Hidden = True
            End If
        End If
    End Sub

    Private Sub chkPrincipalInvestor_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles chkPrincipalInvestor.CheckedChanged
        CheckBoxChangeSearchField()
        If grdInvestors.Rows.Count > 0 Then
            If chkPrincipalInvestor.Checked Then
                grdInvestors.DisplayLayout.Bands(0).Columns("Principal Investor").Hidden = False
            Else
                grdInvestors.DisplayLayout.Bands(0).Columns("Principal Investor").Hidden = True
            End If
        End If
    End Sub

    Private Sub chkType_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles chkType.CheckedChanged
        CheckBoxChangeSearchField()
        If grdInvestors.Rows.Count > 0 Then
            If chkType.Checked Then
                grdInvestors.DisplayLayout.Bands(0).Columns("Type").Hidden = False
            Else
                grdInvestors.DisplayLayout.Bands(0).Columns("Type").Hidden = True
            End If
        End If
    End Sub

    Private Sub chkStyle_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles chkStyle.CheckedChanged
        CheckBoxChangeSearchField()
        If grdInvestors.Rows.Count > 0 Then
            If chkStyle.Checked Then
                grdInvestors.DisplayLayout.Bands(0).Columns("Style").Hidden = False
            Else
                grdInvestors.DisplayLayout.Bands(0).Columns("Style").Hidden = True
            End If
        End If
    End Sub

    Private Sub chkTurnover_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles chkTurnover.CheckedChanged
        CheckBoxChangeSearchField()
        If grdInvestors.Rows.Count > 0 Then
            If chkTurnover.Checked Then
                grdInvestors.DisplayLayout.Bands(0).Columns("Turnover").Hidden = False
            Else
                grdInvestors.DisplayLayout.Bands(0).Columns("Turnover").Hidden = True
            End If
        End If

    End Sub

    Private Sub chkCity_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles chkCity.CheckedChanged
        CheckBoxChangeSearchField()
        If grdInvestors.Rows.Count > 0 Then
            If chkCity.Checked Then
                grdInvestors.DisplayLayout.Bands(0).Columns("City").Hidden = False
            Else
                grdInvestors.DisplayLayout.Bands(0).Columns("City").Hidden = True
            End If
        End If
    End Sub

    Private Sub chkCountry_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles chkCountry.CheckedChanged
        CheckBoxChangeSearchField()
        If grdInvestors.Rows.Count > 0 Then
            If chkCountry.Checked Then
                grdInvestors.DisplayLayout.Bands(0).Columns("Country").Hidden = False
            Else
                grdInvestors.DisplayLayout.Bands(0).Columns("Country").Hidden = True
            End If
        End If
    End Sub

    Private Sub chkParent_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles chkParent.CheckedChanged
        CheckBoxChangeSearchField()
        If grdInvestors.Rows.Count > 0 Then
            If chkParent.Checked Then
                grdInvestors.DisplayLayout.Bands(0).Columns("Parent").Hidden = False
            Else
                grdInvestors.DisplayLayout.Bands(0).Columns("Parent").Hidden = True
            End If
        End If
    End Sub

    Private Sub chkUltimateParent_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles chkUltimateParent.CheckedChanged
        CheckBoxChangeSearchField()
        If grdInvestors.Rows.Count > 0 Then
            If chkUltimateParent.Checked Then
                grdInvestors.DisplayLayout.Bands(0).Columns("Ultimate Parent").Hidden = False
            Else
                grdInvestors.DisplayLayout.Bands(0).Columns("Ultimate Parent").Hidden = True
            End If
        End If
    End Sub

    Private Sub chkMasterType_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles chkMasterType.CheckedChanged
        CheckBoxChangeSearchField()
        If grdInvestors.Rows.Count > 0 Then
            If chkMasterType.Checked Then
                grdInvestors.DisplayLayout.Bands(0).Columns("Master Type").Hidden = False
            Else
                grdInvestors.DisplayLayout.Bands(0).Columns("Master Type").Hidden = True
            End If
        End If
    End Sub

    Private Sub chkActivist_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles chkActivist.CheckedChanged
        CheckBoxChangeSearchField()
        If grdInvestors.Rows.Count > 0 Then
            If chkActivist.Checked Then
                grdInvestors.DisplayLayout.Bands(0).Columns("Activist").Hidden = False
            Else
                grdInvestors.DisplayLayout.Bands(0).Columns("Activist").Hidden = True
            End If
        End If

    End Sub

    Private Sub chkLastReportDate_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles chkLastReportDate.CheckedChanged
        CheckBoxChangeSearchField()
        If grdInvestors.Rows.Count > 0 Then
            If chkLastReportDate.Checked Then
                grdInvestors.DisplayLayout.Bands(0).Columns("Last Report Date").Hidden = False
            Else
                grdInvestors.DisplayLayout.Bands(0).Columns("Last Report Date").Hidden = True
            End If
        End If
    End Sub

    Private Sub chkEquityAssets_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles chkEquityAssets.CheckedChanged
        CheckBoxChangeSearchField()
        If grdInvestors.Rows.Count > 0 Then
            If chkEquityAssets.Checked Then
                grdInvestors.DisplayLayout.Bands(0).Columns("Equity Assets").Hidden = False
            Else
                grdInvestors.DisplayLayout.Bands(0).Columns("Equity Assets").Hidden = True
            End If
        End If
    End Sub

    Private Sub chkStreet1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles chkStreet1.CheckedChanged
        CheckBoxChangeSearchField()
        If grdInvestors.Rows.Count > 0 Then
            If chkStreet1.Checked Then
                grdInvestors.DisplayLayout.Bands(0).Columns("Street1").Hidden = False
            Else
                grdInvestors.DisplayLayout.Bands(0).Columns("Street1").Hidden = True
            End If
        End If
    End Sub

    Private Sub chkStreet2_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles chkStreet2.CheckedChanged
        CheckBoxChangeSearchField()
        If grdInvestors.Rows.Count > 0 Then
            If chkStreet2.Checked Then
                grdInvestors.DisplayLayout.Bands(0).Columns("Street2").Hidden = False
            Else
                grdInvestors.DisplayLayout.Bands(0).Columns("Street2").Hidden = True
            End If
        End If
    End Sub

    Private Sub chkState_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles chkState.CheckedChanged
        CheckBoxChangeSearchField()
        If grdInvestors.Rows.Count > 0 Then
            If chkState.Checked Then
                grdInvestors.DisplayLayout.Bands(0).Columns("State").Hidden = False
            Else
                grdInvestors.DisplayLayout.Bands(0).Columns("State").Hidden = True
            End If
        End If
    End Sub

    Private Sub chkRegion_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles chkRegion.CheckedChanged
        CheckBoxChangeSearchField()
        If grdInvestors.Rows.Count > 0 Then
            If chkRegion.Checked Then
                grdInvestors.DisplayLayout.Bands(0).Columns("Region").Hidden = False
            Else
                grdInvestors.DisplayLayout.Bands(0).Columns("Region").Hidden = True
            End If
        End If
    End Sub

    Private Sub chkMobile_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles chkMobile.CheckedChanged
        CheckBoxChangeSearchField()
        If grdInvestors.Rows.Count > 0 Then
            If chkMobile.Checked Then
                grdInvestors.DisplayLayout.Bands(0).Columns("Mobile").Hidden = False
            Else
                grdInvestors.DisplayLayout.Bands(0).Columns("Mobile").Hidden = True
            End If
        End If
    End Sub

    Private Sub chkTelephone_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles chkTelephone.CheckedChanged
        CheckBoxChangeSearchField()
        If grdInvestors.Rows.Count > 0 Then
            If chkTelephone.Checked Then
                grdInvestors.DisplayLayout.Bands(0).Columns("Telephone").Hidden = False
            Else
                grdInvestors.DisplayLayout.Bands(0).Columns("Telephone").Hidden = True
            End If
        End If
    End Sub

    Private Sub chkExt_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles chkExt.CheckedChanged
        CheckBoxChangeSearchField()
        If grdInvestors.Rows.Count > 0 Then
            If chkExt.Checked Then
                grdInvestors.DisplayLayout.Bands(0).Columns("Extension").Hidden = False
            Else
                grdInvestors.DisplayLayout.Bands(0).Columns("Extension").Hidden = True
            End If
        End If
    End Sub

    Private Sub chkFax_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles chkFax.CheckedChanged
        CheckBoxChangeSearchField()
        If grdInvestors.Rows.Count > 0 Then
            If chkFax.Checked Then
                grdInvestors.DisplayLayout.Bands(0).Columns("Fax").Hidden = False
            Else
                grdInvestors.DisplayLayout.Bands(0).Columns("Fax").Hidden = True
            End If
        End If
    End Sub

    Private Sub chkFax2_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles chkFax2.CheckedChanged
        CheckBoxChangeSearchField()
        If grdInvestors.Rows.Count > 0 Then
            If chkFax2.Checked Then
                grdInvestors.DisplayLayout.Bands(0).Columns("Fax 2").Hidden = False
            Else
                grdInvestors.DisplayLayout.Bands(0).Columns("Fax 2").Hidden = True
            End If
        End If
    End Sub

    Private Sub chkEmail_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles chkEmail.CheckedChanged
        CheckBoxChangeSearchField()
        If grdInvestors.Rows.Count > 0 Then
            If chkEmail.Checked Then
                grdInvestors.DisplayLayout.Bands(0).Columns("Email").Hidden = False
            Else
                grdInvestors.DisplayLayout.Bands(0).Columns("Email").Hidden = True
            End If
        End If
    End Sub

    Private Sub btnEdit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnEdit.Click
        If grdInvestors.Rows.Count = 0 Then
            Exit Sub
        End If
        If (grdInvestors.ActiveRow Is Nothing) Then
            MessageBox.Show(MessageManager.GetMessage("SELECTTHERECORD"), "Warning", MessageBoxButtons.OK, MessageBoxIcon.Information)
            Exit Sub
        Else
            grdInvestors.Selected.Rows.Add(grdInvestors.ActiveRow)
        End If
        If grdInvestors.Selected.Rows().Count = 1 Then
            EditInvestor()
        Else
            MessageBox.Show(MessageManager.GetMessage("SELECTROW"), "Warning", MessageBoxButtons.OK, MessageBoxIcon.Information)
        End If

    End Sub



    Private Sub grdInvestors_AfterSelectChange(ByVal sender As System.Object, ByVal e As Infragistics.Win.UltraWinGrid.AfterSelectChangeEventArgs) Handles grdInvestors.AfterSelectChange
        If (grdInvestors.Selected.Rows.Count > 1) Then
            btnEdit.Enabled = False
        Else
            btnEdit.Enabled = True
        End If
    End Sub

    Private Sub grdInvestors_BeforeEnterEditMode(ByVal sender As System.Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles grdInvestors.BeforeEnterEditMode
        grdInvestors.ActiveRow.Activation = Activation.ActivateOnly

    End Sub

    'Private Sub rdAll_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles rdAll.CheckedChanged
    '    If _OnLoad = False Then
    '        If rdAll.Checked Then
    '            SeachInvestor()
    '            SetTxtSearchText()
    '            rdAll.Focus()
    '        Else
    '            If txtSearchIn.Text = String.Empty Then
    '                SetTxtSearchText()
    '            End If
    '        End If
    '    End If

    'End Sub

    Private Sub txtSearchIn_DoubleClick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtSearchIn.DoubleClick
        txtSearchIn.SelectAll()
    End Sub

    Private Sub grdInvestors_DoubleClickRow(ByVal sender As System.Object, ByVal e As Infragistics.Win.UltraWinGrid.DoubleClickRowEventArgs) Handles grdInvestors.DoubleClickRow
        EditInvestor()
    End Sub

#End Region

    Private Sub rdAll_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles rdAll.Click
        If rdAll.Checked Then
            '  pnlSearchBox.Enabled = False
            SeachInvestor()
            '  pnlSearchBox.Enabled = True
            'SetTxtSearchText()
            'rdAll.Focus()
        End If

    End Sub

    Private Sub rdSearchResult_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles rdSearchResult.Click
        If txtSearchIn.Text = String.Empty Then
            SetTxtSearchText()
        End If
    End Sub

    'Private Sub grdInvestors_InitializeLayout(ByVal sender As Object, ByVal e As Infragistics.Win.UltraWinGrid.InitializeLayoutEventArgs) Handles grdInvestors.InitializeLayout
    '    'grdInvestors.Rows().Item(5)..CellsCollection("")
    '    If e.Layout.Bands(0).Columns("Principal Investor").ToString = String.Empty Then
    '        'rowIndex = e.Layout.Bands(0).Columns("Principal Investor").Index
    '        'e.Layout.Bands(0).Columns() = e.Layout.Bands(0).Columns("InvestorName").ToString
    '    End If

    'End Sub

    Private Sub grdInvestors_InitializeRow(ByVal sender As Object, ByVal e As Infragistics.Win.UltraWinGrid.InitializeRowEventArgs) Handles grdInvestors.InitializeRow
        If e.Row.Cells("Principal Investor").Column.Key = "Principal Investor" Then
            If e.Row.Cells("Principal Investor").Value.ToString = String.Empty Then
                e.Row.Cells("Principal Investor").Value = e.Row.Cells("Investor Name").Value
            End If
        End If
    End Sub

End Class

